import datetime

from mongoengine import Document, StringField, DateTimeField, DictField, IntField, ListField
from pydantic import BaseModel


class JssWFPanterntPage(Document):
    cid = StringField(max_length=10, required=True)
    pagenum = StringField(max_length=10, required=True)
    down_date = StringField(max_length=20, required=True)
    html = StringField()
    create_time = DateTimeField(default=datetime.datetime.now())
    update_time = DateTimeField(default=datetime.datetime.now())


class JssWFPanterntPageModel(BaseModel):
    cid: str
    pagenum: str
    down_date: str
    html: str


class JssWFPanterntDetail(Document):
    cid = StringField(max_length=10, required=True)
    pagenum = StringField(max_length=10, required=True)
    down_date = StringField(max_length=20, required=True)
    rawid = StringField(max_length=50, primary_key=True)
    detail_url = StringField()
    html = StringField()
    export_stat = StringField()
    create_time = DateTimeField(default=datetime.datetime.now())
    update_time = DateTimeField(default=datetime.datetime.now())


class JssWFPanterntDetailModel(BaseModel):
    cid: str
    pagenum: str
    down_date: str
    html: str
    rawid: str
    detail_url: str
    export_stat: str

class WFJournalPage(Document):
    meta = {'db_alias': 'db68'}
    cid = StringField(max_length=10, required=True)
    pagenum = StringField(max_length=10, required=True)
    jsondicts = DictField()
    create_time = DateTimeField(default=datetime.datetime.now())
    update_time = DateTimeField(default=datetime.datetime.now())


class WFJournalPageModel(BaseModel):
    cid: str
    pagenum: str
    jsondicts: dict


class CnkiJournalIdPage(Document):
    meta = {'db_alias': 'db68'}
    pagenum = IntField(primary_key=True)
    html = StringField()
    create_time = DateTimeField(default=datetime.datetime.now())
    update_time = DateTimeField(default=datetime.datetime.now())


class CnkiJournalIdPageModel(BaseModel):
    pagenum: int = 1
    html: str


class CnkiIssue(Document):
    meta = {'db_alias': 'db68'}
    pykm = StringField(primary_key=True)
    html = StringField()
    create_time = DateTimeField(default=datetime.datetime.now())
    update_time = DateTimeField(default=datetime.datetime.now())


class CnkiIssueModel(BaseModel):
    pykm: str
    html: str


class CnkiJournal(Document):
    meta = {'db_alias': 'db68'}
    pykm = StringField(primary_key=True)
    html = StringField()
    create_time = DateTimeField(default=datetime.datetime.now())
    update_time = DateTimeField(default=datetime.datetime.now())


class CnkiJournalModel(BaseModel):
    pykm: str
    html: str


class CnkiArticleId(Document):
    meta = {'db_alias': 'db68'}
    ids = StringField(max_length=20, primary_key=True)
    pykm = StringField(max_length=10, required=True)
    years = StringField(max_length=10, required=True)
    nums = StringField(max_length=10, required=True)
    articlecount = StringField(max_length=10, required=True)
    html = StringField()
    create_time = DateTimeField(default=datetime.datetime.now())
    update_time = DateTimeField(default=datetime.datetime.now())


class CnkiArticleIdModel(BaseModel):
    ids: str
    pykm: str
    years: str
    nums: str
    articlecount: str
    html: str


class CnkiArticleDetail(Document):
    meta = {'db_alias': 'db30_1'}
    articleid = StringField(max_length=20, primary_key=True)
    htmldicts = DictField()
    refdicts = DictField()
    create_time = DateTimeField(default=datetime.datetime.now())
    update_time = DateTimeField(default=datetime.datetime.now())


class CnkiArticleDetailModel(BaseModel):
    articleid: str
    htmldicts: dict
    refdicts: dict


class CnkiArticleDetailRedown(Document):
    meta = {'db_alias': 'db30_1'}
    articleid = StringField(max_length=20, primary_key=True)
    htmldicts = DictField()
    refdicts = DictField()
    create_time = DateTimeField(default=datetime.datetime.now())
    update_time = DateTimeField(default=datetime.datetime.now())


class CnkiArticleDetailRedownModel(BaseModel):
    articleid: str
    htmldicts: dict
    refdicts: dict


class PdfIp(Document):
    meta = {'db_alias': 'db68'}
    ip = StringField(max_length=30, primary_key=True)
    types = IntField(max_length=5, required=True)
    canusecount = IntField(max_length=5, required=True)
    usedcount = IntField(max_length=5, required=True)
    usecountTime = ListField()
    num = IntField(max_length=10, required=True)
    uselisttime = ListField()
    school = StringField(max_length=20, required=True)
    status = IntField(max_length=5, required=True)
    create_time = DateTimeField(default=datetime.datetime.now())
    update_time = DateTimeField(default=datetime.datetime.now())


class PdfIpModel(BaseModel):
    ip: str
    types: int
    canusecount: int
    usedcount: int = 0
    usecountTime: list
    num: int = 0
    uselisttime: list
    status: int
    school: str


class UpdatePdfIpModel(BaseModel):
    ip: str
    time: str
    timelist: list


class CnkiBsRef(Document):
    meta = {'db_alias': 'db68bs'}
    rawid = StringField(max_length=30, primary_key=True)
    create_time = DateTimeField(default=datetime.datetime.now())
    update_time = DateTimeField(default=datetime.datetime.now())


class CnkiBsRefModel(BaseModel):
    rawid: str
    down_date: str
    html: str
